﻿using JT808.Gateway.Abstractions;
using JT808.Gateway.RabbitMQ.Configs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace JT808.Gateway.RabbitMQ
{
    public static class JT808ClientRabbitExtensions
    {
        public static IJT808ClientBuilder AddRabbitNotifyProducer(this IJT808ClientBuilder builder, IConfiguration configuration)
        {
            builder.JT808Builder.Services.Configure<JT808NotifyProducerConfig>(configuration.GetSection("JT808RabbitNotifyProducerConfig"));
            builder.JT808Builder.Services.TryAddSingleton<IJT808NotifyProducer, JT808NotifyProducer>();
            return builder;
        }
        public static IJT808ClientBuilder AddRabbitMsgConsumer(this IJT808ClientBuilder builder, IConfiguration configuration)
        {
            builder.JT808Builder.Services.Configure<JT808MsgConsumerConfig>(configuration.GetSection("JT808RabbitMsgConsumerConfig"));
            builder.JT808Builder.Services.TryAddSingleton<IJT808MsgConsumer, JT808MsgConsumer>();
            return builder;
        }
        public static IJT808ClientBuilder AddRabbitMsgReplyProducer(this IJT808ClientBuilder builder, IConfiguration configuration)
        {
            builder.JT808Builder.Services.Configure<JT808MsgReplyProducerConfig>(configuration.GetSection("JT808RabbitMsgReplyProducerConfig"));
            builder.JT808Builder.Services.TryAddSingleton<IJT808MsgReplyProducer, JT808MsgReplyProducer>();
            return builder;
        }
        public static IJT808ClientBuilder AddRabbitSessionConsumer(this IJT808ClientBuilder builder, IConfiguration configuration)
        {
            builder.JT808Builder.Services.Configure<JT808SessionConsumerConfig>(configuration.GetSection("JT808RabbitSessionConsumerConfig"));
            builder.JT808Builder.Services.TryAddSingleton<IJT808SessionConsumer, JT808SessionConsumer>();
            return builder;
        }
    }
}
